home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6011 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: qualcomm.com!usenet
  2. From: nabbasi@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual Function in private part?
  5. Date: 7 Feb 1996 22:59:48 GMT
  6. Organization: QUALCOMM
  7. Message-ID: <4fbat4$o80@qualcomm.com>
  8. References: <4fa52o$pkb@news1.usa.pipeline.com>
  9. NNTP-Posting-Host: nabbasi.qualcomm.com
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4fa52o$pkb@news1.usa.pipeline.com>, grantp@usa.pipeline.co 
  14. says...
  15. >
  16. >On Feb 06, 1996 10:29:52 in article <Virtual Function in private part?>,
  17. >'g9326161@mcmail.cis.McMaster.CA (Hong Shen)' wrote: 
  18. >>Is there any reasons to make a member function in the private section 
  19. of 
  20. >>a class virtual? 
  21. >> 
  22.  
  23. >Sure, for example:  
  24. >class A { public:   
  25. >void Expand { Left = MakeChild(); Right = MakeChild(); } 
  26. >private: 
  27. >virtual A * MakeChild() { return new A; } 
  28. >A * Left;  A * Right;  
  29. >}; 
  30. >class B { 
  31. > private: 
  32. >  virtual A* MakeChild() { return new B; } 
  33. >}; 
  34. >Now, when you call Expand, the appropriate types of 
  35. >objects will be constructed.   
  36.  
  37. In your class B, the  MakeChild() is declared to return pointer to A, 
  38. yet it returns a pointer to B. Do you not need to do type conversion 
  39. here?
  40.  
  41. Will this compile without errors or at least a warning?
  42.  
  43. Nasser 
  44.  
  45.